//
// Created by Administrator on 2023/8/4.
//

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <unordered_set>
using namespace std;

class Solution {
public:
    vector<vector<int>> findDifference(vector<int> &nums1, vector<int> &nums2) {
        set<int> s1(nums1.begin(), nums1.end());
        set<int> s2(nums2.begin(), nums2.end());
        // 求差集
        set<int> s3;
        set<int> s4;
        set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(), inserter(s3, s3.begin()));
        set_difference(s2.begin(), s2.end(), s1.begin(), s1.end(), inserter(s4, s4.begin()));
        // 返回结果
        vector<vector<int>> res;
        if (!s3.empty())
            res.emplace_back(s3.begin(), s3.end());
        else
            res.emplace_back();
        if (!s4.empty())
            res.emplace_back(s4.begin(), s4.end());
        else
            res.emplace_back();
        return res;
    }
};
class Solution2 {
public:
    vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {
        unordered_set<int> set1, set2;   // nums1 与 nums2 所有元素的哈希集合
        for (int num: nums1) {
            set1.insert(num);
        }
        for (int num: nums2) {
            set2.insert(num);
        }
        vector<vector<int>> res(2);
        for (int num: set1) {
            if (!set2.count(num)) {
                res[0].push_back(num);
            }
        }
        for (int num: set2) {
            if (!set1.count(num)) {
                res[1].push_back(num);
            }
        }
        return res;
    }
};

int main() {
    Solution solution;
    vector<int> nums1 = {1, 2, 3, 3,};
    vector<int> nums2 = {1, 1, 2, 2};
    vector<vector<int>> result = solution.findDifference(nums1, nums2);
    for (auto &i: result) {
        for (int j: i) {
            cout << j << " ";
        }
        cout << endl;


    }
}